package com.dmall.chapter03.section03;

/**
 * 双指针解法
 * 时间复杂度：O(n)
 * 空间复杂度：O(1)
 *
 * @author xiao1.wang
 * @date 2020-12-01 10:41:59
 */
public class Leetcode11V2 {
    public int maxArea(int[] height) {
        int maxArea = 0;
        int left = 0, right = height.length - 1;
        int curArea;
        while (left < right) {
            curArea = height[left] < height[right] ? (right - left) * height[left++] : (right - left) * height[right --];
            maxArea = Math.max(maxArea, curArea);
        }
        return maxArea;
    }

    public static void main(String[] args) {
        int[] height = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        Leetcode11V2 leetcode11 = new Leetcode11V2();
        System.out.println(leetcode11.maxArea(height));
    }
}
